package com.yikaiye.android.yikaiye.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.DataBindingHolder;
import com.yikaiye.android.yikaiye.R;
import com.yikaiye.android.yikaiye.databinding.ItemServiceBinding;
import com.yikaiye.android.yikaiye.model.OrderProgressModel;
import com.yikaiye.android.yikaiye.utils.CommonUtil;
import com.yikaiye.android.yikaiye.utils.UiUtils;
import com.yikaiye.android.yikaiye.widget.flowLayout.FlowLayoutManager;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class OrderProgressAdapter extends BaseQuickAdapter<OrderProgressModel, DataBindingHolder<ItemServiceBinding>> {

    private final Context context;

    public OrderProgressAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected void onBindViewHolder(@NonNull DataBindingHolder<ItemServiceBinding> itemMyServiceBindingDataBindingHolder, int i, @Nullable OrderProgressModel progressModel) {
        ItemServiceBinding binding = itemMyServiceBindingDataBindingHolder.getBinding();
        if (progressModel != null) {
            binding.serviceNameTv.setText(CommonUtil.checkText(progressModel.getServiceName()));
            // 服务状态：0.待办 1.在办 2.暂停 3.已办结 4.已终止
            UiUtils.setServiceStatus(progressModel.getStatus(), binding.serviceStatusTv, context);
            binding.nextIv.setVisibility(View.VISIBLE);
            final FlowLayoutManager flowLayoutManager = new FlowLayoutManager();
            binding.rv.setLayoutManager(flowLayoutManager);
            AttrAdapter adapter = new AttrAdapter();
            binding.rv.setAdapter(adapter);
            String[] attrS = progressModel.getServiceAttr().split(",");
            List<String> attrList = new ArrayList<>(Arrays.asList(attrS));
            adapter.submitList(attrList);

            binding.rv.setOnTouchListener((v, event) -> itemMyServiceBindingDataBindingHolder.itemView.onTouchEvent(event));
        }
    }

    @NonNull
    @Override
    protected DataBindingHolder<ItemServiceBinding> onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int i) {
        return new DataBindingHolder<>(R.layout.item_service, viewGroup);
    }
}
